package com.cc.controller;


import com.cc.AOP.LogOperation;

import com.cc.pojo.Dept;
import com.cc.pojo.Result;
import com.cc.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result list(){
        List<Dept> list= deptService.list();
        return Result.success(list);
    }

    @DeleteMapping
    public Result delete(Integer id){
        log.info("批量删除部门，id：{}",id);
        deptService.delete(id);
        return Result.success();
    }

    @LogOperation
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("添加部门: {}", dept);
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result findById(@PathVariable Integer id){
        log.info("查询员工: id={}", id);
        Dept dept=deptService.findById(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门: {}", dept);
        deptService.update(dept);
        return Result.success();
    }


}
